package sqlites

import (
	"errors"
	"os"
)

//jdbc:sqlite_conf_table:sqlite_conf_table/iotgateway-conf/sqlites.db
func GetSqlitePath(uri string) (string, error) {
	//todo 默认路径读取
	t := uri[5:11]
	if t != "sqlite" {
		return "", errors.New("uri 类型异常" + uri)
	}
	//绝对路径
	path := uri[12:]
	if path[0] == '/' {
		return path, nil
	}

	//相对路径
	if path[0] == '.' {
		curDir, err := os.Getwd()
		if err != nil {
			return "", err
		}
		return curDir + path[0:], nil
	}

	return path, nil
}
